package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.CustomerLoss;
import entity.LayRequest;
import mapper.CustomerLossMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CustomerLossServiceImpl implements CustomerLossService {
    @Autowired
    private CustomerLossMapper customerLossMapper;
    @Override
    public int insert(CustomerLoss customerLoss) {
        int i = customerLossMapper.insert(customerLoss);
        return i;
    }

    @Override
    public List<CustomerLoss> selectAll() {
        return customerLossMapper.selectAll();
    }

    @Override
    public CustomerLoss selectById(Integer id) {
        return customerLossMapper.selectById(id);
    }

    @Override
    public boolean delete(Integer id) {
        return customerLossMapper.delete(id)>0?true:false;
    }

    @Override
    public boolean update(CustomerLoss customerLoss) {
        return customerLossMapper.update(customerLoss)>0?true:false;
    }

    @Override
    public PageInfo<CustomerLoss> selectByPage(Map<String, Object> map) {
        int pageNum=map.get("pageNum")==null?1
                :Integer.valueOf(map.get("pageNum").toString());
        int pageSize=map.get("pageSize")==null?1
                :Integer.valueOf(map.get("pageSize").toString());
        //1.设置当前页和每页记录条数
        PageHelper.startPage(pageNum,pageSize);
        //2.执行查询，startPage之后的第一个查询默认会进行分页
//        List<Admin> admins = adminMapper.selectByMap(map);
        List<CustomerLoss> admins = customerLossMapper.selectByMap(map);
        //3. 创建PageInfo对象，并将返回结果传入。会自动赋值总页数，总记录数当前页等数据
        PageInfo<CustomerLoss> adminPageInfo = new PageInfo<>(admins);
        return adminPageInfo;
    }

    @Override
    public PageInfo<CustomerLoss> selectByPage(LayRequest layRequest) {
        //1.设置当前页和每页记录数
        PageHelper.startPage(layRequest.getPage(),layRequest.getLimit());
        //2.执行查询
        List<CustomerLoss> customerLosses=customerLossMapper.selectByMap(layRequest.getParams());
        //3.创建PageInfo对象
        return new PageInfo<>(customerLosses);
    }

    @Override
    public boolean updateHeadPic(CustomerLoss customerLoss) {
        return customerLossMapper.updateHeadPic(customerLoss)>0?true:false;
    }

    @Override
    public int batchDelete(Integer[] ids) {
        return customerLossMapper.batchDelete(ids);
    }
}
